package com.xbongbong.schedule.task;

import com.xbongbong.schedule.enums.ScheduleTaskTypeEnum;
import com.xbongbong.schedule.task.actions.ScheduleTaskActionExecutor;
import com.xbongbong.schedule.task.actions.TaskActionInterface;
import com.xbongbong.schedule.task.actions.WorkOrderV2TaskActionExecutor;

/**
 * 任务类型执行器枚举
 * @author zheng.li
 */

public enum TaskTypeEnum {

    /**
     * 阶段超时提醒
     */
    STAGE_TIMEOUT_REMIND(ScheduleTaskTypeEnum.STAGE_TIMEOUT_REMIND.getCode(), ScheduleTaskActionExecutor.class),

    /**
     * sla日志任务
     */
    SLA_LOG(ScheduleTaskTypeEnum.SLA_LOG.getCode(), WorkOrderV2TaskActionExecutor.class),

    /**
     * 自定义工单工作流 TODO 这里可能要放在pro服务中，不用转发到工单服务，先放着
     */
    WORK_ORDER_V2_WORKFLOW(ScheduleTaskTypeEnum.WORK_ORDER_V2_WORKFLOW.getCode(), WorkOrderV2TaskActionExecutor.class),
    ;


    TaskTypeEnum(Integer type, Class<? extends TaskActionInterface> executorClass) {
        this.type = type;
        this.executorClass = executorClass;
    }

    /**
     * 任务类型
     */
    private Integer type;

    /**
     * 实际任务处理器
     */
    private Class<? extends TaskActionInterface> executorClass;


    public Integer getType() {
        return type;
    }

    public Class<? extends TaskActionInterface> getExecutorClass() {
        return executorClass;
    }


    public static TaskTypeEnum getByType(Integer type) {
        if (type == null) {
            return null;
        }
        for (TaskTypeEnum e: values()) {
            if (e.getType().equals(type)) {
                return e;
            }
        }

        return null;
    }


}
